import { ref } from "vue";
import { defineStore } from "pinia";
import config from "@/config/index";

// app模块
export const useAppStore = defineStore("app", () => {
  const location = ref({
    lat: 0,
    lng: 0,
  });

  // 获取用户定位
  function getLocation() {
    uni.getLocation({
      altitude: true,
      success(res) {
        const { latitude, longitude } = res;
        location.value = {
          lat: latitude,
          lng: longitude,
        };
        console.log("res", res);
      },
      fail(error) {
        console.log("获取位置失败", error);
      },
    });
  }
  return {
    location,
    getLocation,
  };
});
